//Run placebo regressions and generate figures

set more off

set scheme s1mono


clear all


/*
This loops re-runs our baseline regression with incidents as the 
independent variable for a series of placebo program start dates, 
each separated by six months.
*/
forv i=86/102 {
	use "$data/incFinalMonthlyTehsil", clear
	
	drop if dist=="swa"
    
    label variable totCas "Casualties"
    label variable incidents "Attacks"
    label variable trtXnwa "treat\(\cdot\)nwa"

	replace treat = (yhy>`i')
	replace trtXnwa = treat*nwa

	xtset tehsiln monyr

	xtreg incidents trtXnwa $tmFE , fe cluster(tehsiln)
	eststo est`i'
}	

//save regression results
estout * using "$data/bigInc6.txt", cells(ci_l b ci_u) keep(trtXnwa) replace

import delimited "$data/bigInc6.txt", clear

//put regession results data in graphable format
drop v1

destring, force replace

xpose, clear

g yhy = 85 + _n

label var yhy "Time (Half-Year)"

drop v1 v2

rename v3 ci_l
rename v4 b
rename v5 ci_h

//Output Figure 3 from supplement.
twoway line ci_l yhy, lp(dash) || line b yhy, lp(solid) || line ci_h yhy, lp(dash) ||, yline(0) xline(95, lp(shortdash)) ytitle("Placebo Effect Size ({&delta})") legend(lab(1 "Lower Confidence Bound") lab(2 "Coefficent Estimate") lab(3 "Upper Confidence Bound")) xlabel(86 "Jul 2003" 87 "Jan 2004" 88 "Jul 2004" 89 "Jan 2005" 90 "Jul 2005" 91 "Jan 2006" 92 "Jul 2006" 93 "Jan 2007" 94 "Jul 2007" 95 "Jan 2008" 96 "Jul 2008" 97 "Jan 2009" 98 "Jul 2009" 99 "Jan 2010" 100 "Jul 2010" 101 "Jan 2011" 102 "Jul 2011", angle(45)) ylabel(,angle(0))
graph export "$figures/bigInc6.pdf", replace


/*
Generate another the placebo regression graph with casualties as the
independent variable
*/
clear all

forv i=86/102 {
	use "$data/incFinalMonthlyTehsil", clear
	
	drop if dist=="swa"
    
    label variable totCas "Casualties"
    label variable incidents "Attacks"
    label variable trtXnwa "treat\(\cdot\)nwa"

	replace treat = (yhy>`i')
	replace trtXnwa = treat*nwa

	xtset tehsiln monyr
	
	xtreg totCas trtXnwa $tmFE , fe cluster(tehsiln)
	eststo est`i'
}	

estout * using "$data/bigCas6.txt", cells(ci_l b ci_u) keep(trtXnwa) replace

//Output Figure 4 from supplement.
import delimited "$data/bigCas6.txt", clear

drop v1

destring, force replace

xpose, clear

g yhy = 85 + _n

label var yhy "Time (Half-Year)"

drop v1 v2

rename v3 ci_l
rename v4 b
rename v5 ci_h

twoway line ci_l yhy, lp(dash) || line b yhy, lp(solid) || line ci_h yhy, lp(dash) ||, yline(0) xline(95, lp(shortdash)) ytitle("Placebo Effect Size ({&delta})") legend(lab(1 "Lower Confidence Bound") lab(2 "Coefficent Estimate") lab(3 "Upper Confidence Bound")) xlabel(86 "Jul 2003" 87 "Jan 2004" 88 "Jul 2004" 89 "Jan 2005" 90 "Jul 2005" 91 "Jan 2006" 92 "Jul 2006" 93 "Jan 2007" 94 "Jul 2007" 95 "Jan 2008" 96 "Jul 2008" 97 "Jan 2009" 98 "Jul 2009" 99 "Jan 2010" 100 "Jul 2010" 101 "Jan 2011" 102 "Jul 2011", angle(45)) ylabel(,angle(0))
graph export "$figures/bigCas6.pdf", replace


/*
Generate placebo results for regression specification wiht time-trends.
*/
clear all

forv i=86/102 {
	use "$data/incFinalMonthlyTehsil", clear
	
	drop if dist=="swa"
    
    label variable totCas "Casualties"
    label variable incidents "Attacks"
    label variable trtXnwa "treat\(\cdot\)nwa"

	replace treat = (yhy>`i')
	replace trtXnwa = treat*nwa

	xtset tehsiln monyr
	
	xtreg incidents trtXnwa $tmFE $tmTrds , fe cluster(tehsiln)
	eststo est`i'
}	

estout * using "$data/bigInc6tmTrds.txt", cells(ci_l b ci_u) keep(trtXnwa) replace

import delimited "$data/bigInc6tmTrds.txt", clear

drop v1

destring, force replace

xpose, clear

g yhy = 85 + _n

label var yhy "Time (Half-Year)"

drop v1 v2

rename v3 ci_l
rename v4 b
rename v5 ci_h

//Output Figure 5 from supplement.
twoway line ci_l yhy, lp(dash) || line b yhy, lp(solid) || line ci_h yhy, lp(dash) ||, yline(0) xline(95, lp(shortdash)) ytitle("Placebo Effect Size ({&delta})") legend(lab(1 "Lower Confidence Bound") lab(2 "Coefficent Estimate") lab(3 "Upper Confidence Bound")) xlabel(86 "Jul 2003" 87 "Jan 2004" 88 "Jul 2004" 89 "Jan 2005" 90 "Jul 2005" 91 "Jan 2006" 92 "Jul 2006" 93 "Jan 2007" 94 "Jul 2007" 95 "Jan 2008" 96 "Jul 2008" 97 "Jan 2009" 98 "Jul 2009" 99 "Jan 2010" 100 "Jul 2010" 101 "Jan 2011" 102 "Jul 2011", angle(45)) ylabel(,angle(0))
graph export "$figures/bigInc6tmTrds.pdf", replace

clear all

forv i=86/102 {
	use "$data/incFinalMonthlyTehsil", clear
	
	drop if dist=="swa"
    
    label variable totCas "Casualties"
    label variable incidents "Attacks"
    label variable trtXnwa "treat\(\cdot\)nwa"

	replace treat = (yhy>`i')
	replace trtXnwa = treat*nwa

	xtset tehsiln monyr
	
	xtreg totCas trtXnwa $tmFE $tmTrds , fe cluster(tehsiln)
	eststo est`i'
}	

estout * using "$data/bigCas6tmTrds.txt", cells(ci_l b ci_u) keep(trtXnwa) replace

import delimited "$data/bigCas6tmTrds.txt", clear

drop v1

destring, force replace

xpose, clear

g yhy = 85 + _n

label var yhy "Time (Half-Year)"

drop v1 v2

rename v3 ci_l
rename v4 b
rename v5 ci_h

//Output Figure 6 from supplement.
twoway line ci_l yhy, lp(dash) || line b yhy, lp(solid) || line ci_h yhy, lp(dash) ||, yline(0) xline(95, lp(shortdash)) ytitle("Placebo Effect Size ({&delta})") legend(lab(1 "Lower Confidence Bound") lab(2 "Coefficent Estimate") lab(3 "Upper Confidence Bound")) xlabel(86 "Jul 2003" 87 "Jan 2004" 88 "Jul 2004" 89 "Jan 2005" 90 "Jul 2005" 91 "Jan 2006" 92 "Jul 2006" 93 "Jan 2007" 94 "Jul 2007" 95 "Jan 2008" 96 "Jul 2008" 97 "Jan 2009" 98 "Jul 2009" 99 "Jan 2010" 100 "Jul 2010" 101 "Jan 2011" 102 "Jul 2011", angle(45)) ylabel(,angle(0))
graph export "$figures/bigCas6tmTrds.pdf", replace



/*
Generate placebo results for regression specification wiht time-trends
and additional control variables.
*/
clear all

forv i=86/102 {
	use "$data/incFinalMonthlyTehsil", clear
	
	drop if dist=="swa"
    
    label variable totCas "Casualties"
    label variable incidents "Attacks"
    label variable trtXnwa "treat\(\cdot\)nwa"

	replace treat = (yhy>`i')
	replace trtXnwa = treat*nwa

	xtset tehsiln monyr
	
	xtreg incidents trtXnwa $tmFE $tmTrds $ctrls , fe cluster(tehsiln)
	eststo est`i'
}	

estout * using "$data/bigInc6tmTrdsWctrls.txt", cells(ci_l b ci_u) keep(trtXnwa) replace

import delimited "$data/bigInc6tmTrdsWctrls.txt", clear

drop v1

destring, force replace

xpose, clear

g yhy = 85 + _n

label var yhy "Time (Half-Year)"

drop v1 v2

rename v3 ci_l
rename v4 b
rename v5 ci_h

//Output Figure 7 from supplement.
twoway line ci_l yhy, lp(dash) || line b yhy, lp(solid) || line ci_h yhy, lp(dash) ||, yline(0) xline(95, lp(shortdash)) ytitle("Placebo Effect Size ({&delta})") legend(lab(1 "Lower Confidence Bound") lab(2 "Coefficent Estimate") lab(3 "Upper Confidence Bound")) xlabel(86 "Jul 2003" 87 "Jan 2004" 88 "Jul 2004" 89 "Jan 2005" 90 "Jul 2005" 91 "Jan 2006" 92 "Jul 2006" 93 "Jan 2007" 94 "Jul 2007" 95 "Jan 2008" 96 "Jul 2008" 97 "Jan 2009" 98 "Jul 2009" 99 "Jan 2010" 100 "Jul 2010" 101 "Jan 2011" 102 "Jul 2011", angle(45)) ylabel(,angle(0))
graph export "$figures/bigInc6tmTrdsWctrls.pdf", replace


clear all

forv i=86/102 {
	use "$data/incFinalMonthlyTehsil", clear
	
	drop if dist=="swa"
    
    label variable totCas "Casualties"
    label variable incidents "Attacks"
    label variable trtXnwa "treat\(\cdot\)nwa"

	replace treat = (yhy>`i')
	replace trtXnwa = treat*nwa

	xtset tehsiln monyr
	
	xtreg totCas trtXnwa $tmFE $tmTrds $ctrls , fe cluster(tehsiln)
	eststo est`i'
}	

estout * using "$data/bigCas6tmTrdsWctrls.txt", cells(ci_l b ci_u) keep(trtXnwa) replace

import delimited "$data/bigCas6tmTrdsWctrls.txt", clear

drop v1

destring, force replace

xpose, clear

g yhy = 85 + _n

label var yhy "Time (Half-Year)"

drop v1 v2

rename v3 ci_l
rename v4 b
rename v5 ci_h

//Output Figure 8 from supplement.
twoway line ci_l yhy, lp(dash) || line b yhy, lp(solid) || line ci_h yhy, lp(dash) ||, yline(0) xline(95, lp(shortdash)) ytitle("Placebo Effect Size ({&delta})") legend(lab(1 "Lower Confidence Bound") lab(2 "Coefficent Estimate") lab(3 "Upper Confidence Bound")) xlabel(86 "Jul 2003" 87 "Jan 2004" 88 "Jul 2004" 89 "Jan 2005" 90 "Jul 2005" 91 "Jan 2006" 92 "Jul 2006" 93 "Jan 2007" 94 "Jul 2007" 95 "Jan 2008" 96 "Jul 2008" 97 "Jan 2009" 98 "Jul 2009" 99 "Jan 2010" 100 "Jul 2010" 101 "Jan 2011" 102 "Jul 2011", angle(45)) ylabel(,angle(0))
graph export "$figures/bigCas6tmTrdsWctrls.pdf", replace


/*
Generate placebo results for regression specification wiht time-trends
and additional control variables with tehsil-specific coefficients.
*/
clear all

forv i=86/102 {
	use "$data/incFinalMonthlyTehsil", clear
	
	drop if dist=="swa"
    
    label variable totCas "Casualties"
    label variable incidents "Attacks"
    label variable trtXnwa "treat\(\cdot\)nwa"

	replace treat = (yhy>`i')
	replace trtXnwa = treat*nwa

	xtset tehsiln monyr
	
	xtreg incidents trtXnwa $tmFE $tmTrds $ctrls2 , fe cluster(tehsiln)
	eststo est`i'
}	

estout * using "$data/bigInc6tmTrdsHetCtrls.txt", cells(ci_l b ci_u) keep(trtXnwa) replace

import delimited "$data/bigInc6tmTrdsHetCtrls.txt", clear

drop v1

destring, force replace

xpose, clear

g yhy = 85 + _n

label var yhy "Time (Half-Year)"

drop v1 v2

rename v3 ci_l
rename v4 b
rename v5 ci_h

//Output Figure 9 from supplement.
twoway line ci_l yhy, lp(dash) || line b yhy, lp(solid) || line ci_h yhy, lp(dash) ||, yline(0) xline(95, lp(shortdash)) ytitle("Placebo Effect Size ({&delta})") legend(lab(1 "Lower Confidence Bound") lab(2 "Coefficent Estimate") lab(3 "Upper Confidence Bound")) xlabel(86 "Jul 2003" 87 "Jan 2004" 88 "Jul 2004" 89 "Jan 2005" 90 "Jul 2005" 91 "Jan 2006" 92 "Jul 2006" 93 "Jan 2007" 94 "Jul 2007" 95 "Jan 2008" 96 "Jul 2008" 97 "Jan 2009" 98 "Jul 2009" 99 "Jan 2010" 100 "Jul 2010" 101 "Jan 2011" 102 "Jul 2011", angle(45)) ylabel(,angle(0))
graph export "$figures/bigInc6tmTrdsHetCtrls.pdf", replace


clear all

forv i=86/102 {
	use "$data/incFinalMonthlyTehsil", clear
	
	drop if dist=="swa"
    
    label variable totCas "Casualties"
    label variable incidents "Attacks"
    label variable trtXnwa "treat\(\cdot\)nwa"

	replace treat = (yhy>`i')
	replace trtXnwa = treat*nwa

	xtset tehsiln monyr
	
	xtreg totCas trtXnwa $tmFE $tmTrds $ctrls2 , fe cluster(tehsiln)
	eststo est`i'
}	

estout * using "$data/bigCas6tmTrdsHetCtrls.txt", cells(ci_l b ci_u) keep(trtXnwa) replace

import delimited "$data/bigCas6tmTrdsHetCtrls.txt", clear

drop v1

destring, force replace

xpose, clear

g yhy = 85 + _n

label var yhy "Time (Half-Year)"

drop v1 v2

rename v3 ci_l
rename v4 b
rename v5 ci_h

//Output Figure 10 from supplement.
twoway line ci_l yhy, lp(dash) || line b yhy, lp(solid) || line ci_h yhy, lp(dash) ||, yline(0) xline(95, lp(shortdash)) ytitle("Placebo Effect Size ({&delta})") legend(lab(1 "Lower Confidence Bound") lab(2 "Coefficent Estimate") lab(3 "Upper Confidence Bound")) xlabel(86 "Jul 2003" 87 "Jan 2004" 88 "Jul 2004" 89 "Jan 2005" 90 "Jul 2005" 91 "Jan 2006" 92 "Jul 2006" 93 "Jan 2007" 94 "Jul 2007" 95 "Jan 2008" 96 "Jul 2008" 97 "Jan 2009" 98 "Jul 2009" 99 "Jan 2010" 100 "Jul 2010" 101 "Jan 2011" 102 "Jul 2011", angle(45)) ylabel(,angle(0))
graph export "$figures/bigCas6tmTrdsHetCtrls.pdf", replace
